#!/usr/bin/env python2.7
# -*- coding:utf-8 -*- 

# china_9km_anl.py

import os, sys
from metlib.kits import *
from datakeeper.models import DataSet, DatasetMold

mold_name = 'Solar_Sat'

ds_infos = {
    'fy2c': {
        'min_lon': 45.0,
        'max_lon': 165.0,
        'min_lat': -60.0,
        'max_lat': 60.0,
        'lon_delta': 1.0,
        'lat_delta': 1.0,
        'begdt': '20060101',
        'enddt': '20090101',
        'years': ['2006', '2007', '2008'],
        'sat': 'fy2c',
        'desc': '风云2C卫星数据',
        'public': True,
        'priority': 110,
    },
    'fy2d': {
        'min_lon': 26.5,
        'max_lon': 146.5,
        'min_lat': -60.0,
        'max_lat': 60.0,
        'lon_delta': 1.0,
        'lat_delta': 1.0,
        'begdt': '20080101',
        'enddt': '20150101',
        'years': ['2008', '2009', '2010', '2011', '2012', '2013', '2014'],
        'sat': 'fy2d',
        'desc': '风云2D卫星数据',
        'public': True,
        'priority': 120,
    },
    'fy2e': {
        'min_lon': 27.0,
        'max_lon': 147.0,
        'min_lat': -60.0,
        'max_lat': 60.0,
        'lon_delta': 1.0,
        'lat_delta': 1.0,
        'begdt': '20100101',
        'enddt': '20150101',
        'years': ['2010', '2011', '2012', '2013', '2014'],
        'sat': 'fy2e',
        'desc': '风云2E卫星数据',
        'public': True,
        'priority': 130,
    },
    'fy2f': {
        'min_lon': 52.0,
        'max_lon': 172.0,
        'min_lat': -60.0,
        'max_lat': 60.0,
        'lon_delta': 1.0,
        'lat_delta': 1.0,
        'begdt': '20130101',
        'enddt': '20150101',
        'years': ['2013', '2014'],
        'sat': 'fy2f',
        'desc': '风云2F卫星数据',
        'public': True,
        'priority': 140,
    },
    'fy2c_cor': {
        'min_lon': 45.0,
        'max_lon': 165.0,
        'min_lat': -60.0,
        'max_lat': 60.0,
        'lon_delta': 1.0,
        'lat_delta': 1.0,
        'begdt': '20060101',
        'enddt': '20090101',
        'years': ['2006', '2007', '2008'],
        'sat': 'fy2c_cor',
        'desc': '风云2C卫星数据(修正)',
        'public': False,
        'priority': 101,
    },
    'fy2d_cor': {
        'min_lon': 26.5,
        'max_lon': 146.5,
        'min_lat': -60.0,
        'max_lat': 60.0,
        'lon_delta': 1.0,
        'lat_delta': 1.0,
        'begdt': '20080101',
        'enddt': '20120101',
        'years': ['2008', '2009', '2010', '2011'],
        'sat': 'fy2d_cor',
        'desc': '风云2D卫星数据(修正)',
        'public': False,
        'priority': 102,
    },
    'fy2e_cor': {
        'min_lon': 27.0,
        'max_lon': 147.0,
        'min_lat': -60.0,
        'max_lat': 60.0,
        'lon_delta': 1.0,
        'lat_delta': 1.0,
        'begdt': '20100101',
        'enddt': '20120101',
        'years': ['2010', '2011'],
        'sat': 'fy2e_cor',
        'desc': '风云2E卫星数据(修正)',
        'public': False,
        'priority': 103,
    },
}
ds_desc = u'大贤的风云系列静止卫星数据'


def run():
    for i, (ds_name, info) in enumerate(ds_infos.items()):
        try:
            raise DataSet.DoesNotExist
            ds = DataSet.objects.get(name=ds_name)
            print "%s exists, not creating." % ds_name
        except DataSet.DoesNotExist:
            try:
                mold = DatasetMold.objects.get(name=mold_name)
            except DatasetMold.DoesNotExist:
                print "No such dataset-mold: " + mold_name
                sys.exit(1)
            print "Creating dataset: %s ..." % ds_name
            priority = info.pop('priority')
            ds = DataSet(
                name=ds_name,
                desc=info['desc'],
                creator='dxwind',
                version='1.0',
                mold=mold,
                priority=priority,
                protect_data=True,
                public=info.get('public', True),
                free=True,
            )
            ds.info = info

            ds.save()
